package logics 
{
	import constants.Events;
	import constants.States;
	import constants.Structures;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	
	import interfaces.logos;
	import logics.StateMachine;
	/**
	 * ...
	 * @author parasitic
	 */
	public class EventDispatch extends Logic
	{
		private function mousedown_handler(e:MouseEvent):void
		{
			switch(machine.getState())
			{
				case States.FREE:
					break;
					
				case States.NOW_BUILDING:
					dispatchEvent(new CustomEvent(Events.PLACE_BUILDING));
					break;
				
				default:
					break;
			}
		}
		
		private function mouseup_handler(e:MouseEvent):void
		{
			
		}
		
		private function mousemove_handler(e:MouseEvent):void
		{
			
		}
		
		private function keydown_handler(e:KeyboardEvent):void
		{
			switch(machine.getState())
			{
				
				case States.FREE:
				
				switch(e.keyCode)
				{
					case 37:
						dispatchEvent( new CustomEvent(Events.CAMERA_MOVING, States.LEFT) );
						break;
					
					case 38:
						dispatchEvent( new CustomEvent(Events.CAMERA_MOVING, States.UP) );
						break;
					
					case 39:
						dispatchEvent( new CustomEvent(Events.CAMERA_MOVING, States.RIGHT) );
						break;
						
					case 40:
						dispatchEvent( new CustomEvent(Events.CAMERA_MOVING, States.DOWN) );
						break;
					
					case 49:
						dispatchEvent( new CustomEvent(Events.START_BUILD, Structures.GENERATOR) );
						break;
					
					case 50:
						dispatchEvent( new CustomEvent(Events.START_BUILD, Structures.RESEARCH) );
						break;
					
					case 51:
						dispatchEvent( new CustomEvent(Events.START_BUILD, Structures.SHIPYARD) );
						break;
				
					case 52:
						dispatchEvent( new CustomEvent(Events.START_BUILD, Structures.TURRET) );
						break;
				}
				break;
			}
		}
		
		private function keyup_handler(e:KeyboardEvent):void
		{
			
		}
		
		override protected function init(e:Event):void
		{
			super.init(e);
			newListener(MouseEvent.MOUSE_DOWN, mousedown_handler);
			newListener(MouseEvent.MOUSE_UP, mouseup_handler);
			newListener(MouseEvent.MOUSE_MOVE, mousemove_handler);
			newListener(KeyboardEvent.KEY_DOWN, keydown_handler);
			newListener(KeyboardEvent.KEY_UP, keyup_handler);
		}
		
		public function EventDispatch(s:StateMachine) 
		{
			super(s);
		}
		
	}

}